import reshandler from 'services/response-handler'
/*
 * 卡券详情参数卡券id活动id
 */
function makeData(data) {
    console.log(data);
    let type ;
    let _useDate;
    let _amount;
    let isHideUse = false;
    switch (data.coupon.type) {
        case '0':
            type = '红包券'
            break;
        case '1':
            type = '优惠券'
            break;
        case '2':
            type = '实物券'
            break;
        case '3':
            type = '现金券'
            break;
        case '4':
            type = '团购券'
            break;
        case '5':
            type = '秒杀券'
            break;
        case '6':
            type = 'N元抢购券'
            break;
        case '7':
            type = '抵价券'
            break;
        case '8':
            type = '包邮券'
            break;
        case '9':
            type = '满减券'
            break;
        case '10':
            type = '折扣券'
            break;
        case '11':
            type = '满送券'
            break;
        case '12':
            type = '套餐券'
            break;
        case '13':
            type = '权益券'
            break;
        default :
            type = '未知类型券'
            break;
    }

    if(data.coupon.type === '13'){
        isHideUse = true;
    }
    if (data.coupon.endDate === undefined){
        _useDate = '长期有效'
    } else if (data.coupon.beginDate === undefined){
        _useDate = '至' + data.coupon.endDate
    }else{
        _useDate =  data.coupon.beginDate  + '至' + data.coupon.endDate
    }
    if (data.coupon.amount === '') {
        _amount = '暂无金额'
    } else {
        _amount = '￥' + data.coupon.amount
    }
    return {
        useDate: _useDate,
        type: data.coupon.type ? data.coupon.type : data.coupon.type,
        cardType:type,
        shopName: data.coupon.shop.name ? data.coupon.shop.name : '',
        code: data.coupon.code ? data.coupon.code : '',
        rule: data.coupon.introduction ? data.coupon.introduction :'',
        activityId: data.coupon.activityId ? data.coupon.activityId : '',
        amount: _amount,
        minimumPrice: data.coupon.minimumPrice ? data.coupon.minimumPrice : '',
        name: data.coupon.name ? data.coupon.name : '',
        state: data.coupon.state ? data.coupon.state : '',
        isHideUse: isHideUse,
        shop: data.coupon.shop ? data.coupon.shop : ''

    }
}
export default function (params, success, fail) {
    this.$.get(params).then(reshandler.success(success, fail, makeData), reshandler.error(fail))
}
